package com.example.composestudy

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import com.example.composestudy.data.ListItemBean

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun StudyPageList(
    navController: NavHostController,
    title: String,
    list: List<ListItemBean>,
) {
    Scaffold(
        modifier = Modifier.fillMaxSize(),
        topBar = {
            TopAppBar(
                title = {
                    Text(title)
                },
                navigationIcon = {
                    IconButton(onClick = {
                        navController.navigateUp()
                    }) {
                        Icon(
                            imageVector = Icons.Default.ArrowBack,
                            contentDescription = "Back"
                        )
                    }
                },
            )
        }
    ) { innerPadding ->
        LazyColumn(
            modifier = Modifier
                .fillMaxSize()
                .padding(innerPadding)
        ) {
            items(list.size) {
                val item = list[it]
                ListItem(
                    modifier = Modifier.clickable {
                        navController.navigate(item.router)
                    },
                    text = { Text(text = item.title) }
                )
                if (it != list.lastIndex) {
                    Divider()
                }
            }
        }
    }
}